package Test1;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ex2 extends JFrame {

	private JPanel contentPane;
	private JLabel lblNewLabel;
	private JTextArea non;
	private JLabel label;
	private JTextArea search;
	private JButton button;
	private JButton button_1;
	private JLabel label_1;
	private JScrollPane scrollPane;
	private JTextArea res;
	String[] words=new String[5];
	int cnt=0;
	//int temp;
	private JButton button_2;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ex2 frame = new ex2();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ex2() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		contentPane.add(getLblNewLabel());
		contentPane.add(getNon());
		contentPane.add(getLabel());
		contentPane.add(getSearch());
		contentPane.add(getButton());
		
		contentPane.add(getLabel_1());
		contentPane.add(getScrollPane());
		contentPane.add(getButton_2());
	}
	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("금지어");
			lblNewLabel.setBounds(12, 21, 57, 15);
		}
		return lblNewLabel;
	}
	private JTextArea getNon() {
		if (non == null) {
			non = new JTextArea();
			non.setBounds(69, 17, 240, 24);
		}
		return non;
	}
	private JLabel getLabel() {
		if (label == null) {
			label = new JLabel("검색어");
			label.setBounds(12, 67, 57, 15);
		}
		return label;
	}
	private JTextArea getSearch() {
		if (search == null) {
			search = new JTextArea();
			search.setBounds(69, 63, 240, 24);
		}
		return search;
	}
	private JButton getButton() {
		if (button == null) {
			button = new JButton("추가");
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					
					boolean flag=false;
					if(!non.getText().equals("")) flag=true;
					if(flag){
						
						words[cnt]=non.getText();
						cnt++;
					}
					non.setText("");
			
					
				}
			});
			button.setBounds(349, 14, 73, 29);
		}
		return button;
	}
	
	private JLabel getLabel_1() {
		if (label_1 == null) {
			label_1 = new JLabel("검색결과");
			label_1.setBounds(12, 111, 57, 15);
		}
		return label_1;
	}
	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setBounds(12, 136, 410, 116);
			scrollPane.setViewportView(getRes());
		}
		return scrollPane;
	}
	private JTextArea getRes() {
		if (res == null) {
			res = new JTextArea();
		}
		return res;
	}
	private JButton getButton_2() {
		if (button_2 == null) {
			button_2 = new JButton("검색");
			button_2.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					boolean flag=false;

					for (int i = 0;i<cnt; i++) {
						if (search.getText().contains(words[i])) {
							flag=true;
						}
					}
					if(flag==true){
						res.setText("금지어입니다.\n");
					}else{
						res.append(search.getText()+"가 검색되었습니다.\n");
					}

					search.setText("");
					search.requestFocus();
				}
			});
			button_2.setBounds(349, 67, 73, 29);
		}
		return button_2;
	}
}
